#!/bin/bash
## Install and Configure OpenGL
apt-get install -y --no-install-recommends \
    x11-xserver-utils libxau6 libxdmcp6 libxcb1 libxext6 libx11-6 dbus-x11\
    libglvnd0 libgl1 libglx0 libegl1 libgles2 libglvnd-dev \
    libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev mesa-utils
# configure EGL vendor
mkdir -p /usr/share/glvnd/egl_vendor.d/ 
echo -e "{\n\
\"file_format_version\" : \"1.0.0\",\n\
\"ICD\": {\n\
    \"library_path\": \"libEGL_nvidia.so.0\"\n\
}\n\
}" > /usr/share/glvnd/egl_vendor.d/10_nvidia.json
## Install and Configure Vulkan
apt-get install -y --no-install-recommends vulkan-tools && \
VULKAN_API_VERSION=$(dpkg -s libvulkan1 | grep -oP 'Version: [0-9|\.]+' | grep -oP '[0-9]+(\.[0-9]+)(\.[0-9]+)') && \
mkdir -p /etc/vulkan/icd.d/ && \
echo -e "{\n\
\"file_format_version\" : \"1.0.0\",\n\
\"ICD\": {\n\
    \"library_path\": \"libGLX_nvidia.so.0\",\n\
        \"api_version\" : \"${VULKAN_API_VERSION}\"\n\
}\n\
}" > /etc/vulkan/icd.d/nvidia_icd.json
apt-get install -y --no-install-recommends xauth xfce4 xfce4-goodies xubuntu-icon-theme
# remove and disable screensaver
apt-get remove -y xfce4-screensaver --purge
# add cuda toolkit to PATH
echo "export PATH=\$PATH:/usr/local/cuda/bin" > /etc/profile.d/cuda.sh